package com.docking.heylo.web.controller;

import com.docking.heylo.constant.SystemConstant;
import com.docking.heylo.dao.entity.Post;
import com.docking.heylo.dao.entity.PostComments;
import com.docking.heylo.service.IPostService;
import com.docking.heylo.utils.HeyloMessageSource;
import com.docking.heylo.web.dto.PostCommentsDto;
import com.docking.heylo.web.dto.PostDto;
import com.docking.heylo.web.dto.PushPostDto;
import com.docking.heylo.web.utils.ResultUtil;
import com.docking.heylo.web.vo.BaseVo;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/***
 * 作品
 */
@RestController
@RequestMapping("/post")
public class PostController {

    @Autowired
    private IPostService postService;

    @Autowired
    private HeyloMessageSource ms;

    /***
     * 发布作品
     *
     * @return
     */
    @PostMapping("/pushPost")
    public BaseVo pushPost(@RequestBody PushPostDto dto){
        postService.pushPost(dto);
        return ResultUtil.success(ms.getMessage(SystemConstant.success));
    }

    /***
     * 获取指定人的作品
     *
     * @return
     */
    @PostMapping("/postByUserId")
    public BaseVo postByUserId(@RequestBody PostDto postDto){
        PageInfo<Map<String,Object>> posts = postService.postByUserId(postDto);
        return ResultUtil.success(ms.getMessage(SystemConstant.success), posts);
    }


    /***
     * 举报作品评论
     *
     * @param post
     * @return
     */
    @RequestMapping("/comments/report")
    public BaseVo postCommentsReport(@RequestBody PostDto post){
        postService.commentsReport(post);
        return ResultUtil.success(ms.getMessage(SystemConstant.success));
    }

    /***
     * 获取指定作品的评论
     *
     * @return
     */
    @PostMapping("/postComments")
    public BaseVo postComments(@RequestBody PostCommentsDto postCommentsDto){
        PageInfo<Map<String,Object>> comments = postService.postComments(postCommentsDto);
        return ResultUtil.success(ms.getMessage(SystemConstant.success), comments);
    }

    /***
     * 发布评论
     *
     * @return
     */
    @PostMapping("/pushPostComment")
    public BaseVo pushPostComment(@RequestBody PostComments postComments){
        postService.pushPostComment(postComments);
        return ResultUtil.success(ms.getMessage(SystemConstant.success));
    }

    /***
     * 查看用户最新的作品
     *
     * @param post
     * @return
     */
    @RequestMapping("/lastPostForUser")
    public BaseVo lastPostForUser(@RequestBody Post post){
        Post lastPost = postService.selectLastPostForUser(post.getUserId());
        return ResultUtil.success(ms.getMessage(SystemConstant.success),lastPost);
    }

    /***
     * 作品面板
     *
     * @return
     */
    @RequestMapping("/panel")
    public BaseVo panel(@RequestBody Post post){
        return ResultUtil.success(ms.getMessage(SystemConstant.success),postService.panel(post.getId()));
    }

    /***
     * 点赞
     *
     * @return
     */
    @RequestMapping("/like")
    public BaseVo like(@RequestBody PostDto post){
        postService.like(post);
        return ResultUtil.success(ms.getMessage(SystemConstant.success));
    }


    /***
     * 举报
     *
     * @param post
     * @return
     */
    @RequestMapping("/report")
    public BaseVo report(@RequestBody PostDto post){
        postService.report(post);
        return ResultUtil.success(ms.getMessage(SystemConstant.success));
    }

    /***
     * 上滑
     *
     * @return
     */
    @RequestMapping("/slidingUp")
    public BaseVo slidingUp(@RequestBody PostDto post){
        postService.slidingUp(post);
        return ResultUtil.success(ms.getMessage(SystemConstant.success));
    }


    /***
     * 移除作品
     *
     * @return
     */
    @PostMapping("/remove")
    public BaseVo remove(@RequestBody Post post){
        postService.remove(post);
        return ResultUtil.success(ms.getMessage(SystemConstant.success));
    }





}
